const http = require('http')
const path = require('path')
const url = require('url')
const fs = require('fs')

// 根目录  / => 服务器中的地址
const webRoot = path.resolve('./www')

http.createServer((req, res) => {
  let { pathname } = url.parse(req.url, true)
  if ('/favicon.ico' == pathname) return;
  fs.createReadStream(path.join(webRoot, pathname)).pipe(res)
}).listen(4000, () => console.log('http://localhost:4000'))